<!--Generate by Kevin's CodeBuilder 2021-09-12 16:09:23-->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title></title>
    <head th:replace="source::header">
    </head>
</head>
<body>
    <div id="k_page_erea" class="form_main_wrap">
        <div class="k_form_grid">
            <table id="datagrid"></table>
        </div>
        <div class="k_form_condition" style="padding:12px 14px;">
            <table class="k_form_table" id="k_form_query_wrap">
                <tr>
                    <td class="label label100">[(${Lang.common_query_from})]</td>
                    <td>
                        <input id="menuTree" name="menuTree" class="form_input form_input30" type="text" />
                        <span style="padding-left:30px">
								<button class="k_common_button" id="search_btn">
									<i class="fa fa-search"></i>
									[(${Lang.common_search})]
								</button>
						 </span>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    </div>
    <script type="application/javascript" th:inline="javascript">
         var curdObj,
             $win,
             height = 352,
             gridOpts = [(${dataGridJson})],//获取datagrid配置json
             title = "[(${Lang.func_windowTitle})]";//国际化语言
             gridOpts.title = title;

          window.closeWindow = function(){
              curdObj.reload();
              $win.close();
          };

         $B.DomUtils.onDomLoaded(function () {
             //菜单树
             new $B.Combox("menuTree", {
                 url: $B.getHttpHost()+"menu/query",
                 isTree:true,
                 getIdAndTxt:true,
                 inputImdSearch:false,
                 multiple:false,
                 readOnly: true
             });


             var dg =  document.getElementById("datagrid");
             //设置查询参数
             gridOpts.setParams = function(){
                 console.log("set params");
                 let $i = document.getElementById("menuTree_input");
                 let idVal = $B.DomUtils.attribute($i,"_id");
                 if(idVal && idVal !== ""){
                     let v = idVal.split(";");
                     return {menuId:v[v.length-1]};
                 }
                 return {};
             };
             gridOpts.title = "";
             gridOpts.pageArea = "k_page_erea";
             gridOpts.fit2height = true;
             gridOpts.oprColWidth = 235;
             //gridOpts.idField = "id";
             //gridOpts.sortField = {"orderIndex" : "asc"};
             curdObj = new $B.CURD(dg, gridOpts);

             //输入框绑定清理按钮
             $B.bindInputClear("k_form_query_wrap");

             $B.DomUtils.click(document.getElementById("search_btn"),()=>{
                  curdObj.reload();
             });
         });
         //打开form.html
        function _openForm(prs,isUpdate,winTitle){
             console.log(prs,isUpdate,winTitle);
             var opts = {
                 dataType:'html',
                 title:winTitle ? winTitle:title,
                 width:750,
                 height:height
             };
             if(prs){
                 opts.params = prs;
             }
             curdObj.window(opts,isUpdate);
         };
         /******工具栏事件集合******/
         window.buttonEvents = {
             addFn:function(prs){
                 _openForm(undefined,false,'[(${Lang.common_add_title})]');
             },
             updateFn:function(prs){
                 _openForm(undefined,true,'[(${Lang.common_update_title})]');
             },
             deleteFn:function(prs){
                 curdObj.delChecked();
             },
             lineUpdateFn:function(prs){
                 _openForm({id:prs.id},true,'[(${Lang.common_update_title})]');
             },
             lineDeleteFn:function(prs){
                 curdObj.deleteData([prs.id]);
             },
             exportFn:function () {
                 $win = $B.window({
                     title:'导出',
                     width:460,
                     height:260,
                     fixed:true,
                     dataType :'iframe',
                     url:$B.getHttpHost()+"func/page/export"
                 });
             },
             importFn:function () {
                 $win = $B.window({
                     header:false,
                     title:'导入',
                     width:500,
                     height:200,
                     fixed:true,
                     dataType :'iframe',
                     url:$B.getHttpHost()+"func/page/import"
                 });
             }
         };
         function formatMenu(cval,rval) {
             if(rval.extFeildsMap.menuText){
                    return rval.extFeildsMap.menuText;
             }
             return "-";
         }

         function switchEnable(name,val,oldVal,oldClazz){
             let childs = $B.DomUtils.children(this,"span");
             let $input = this.lastChild;
             let id =  $B.DomUtils.attribute($input,"dataid");
             let prs = {id : id,isLog: val,"__skipSaveFilter":'1' }; //,"__skipSaveFilter":'1'
             $B.request({
                 waiting:true,
                 url : $B.getHttpHost(ctxPath) + "func/update",
                 data:prs,
                 fail:function (msg,data) {
                     for(let i =0 ; i < childs.length ; i++){
                         $B.DomUtils.attribute(childs[i],oldClazz[i]);
                     }
                     $input.value = oldVal;
                     $B.error(msg,1.5);
                 },ok:function () {
                     $B.success("修改成功！",1.6);
                 }
             });
         }

         function formatLog(cval,rval) {
             let $wap = this.firstChild.firstChild;
             let $in = $B.DomUtils.createEl('<input dataid="'+rval.id+'" id="isLog" name="isLog" value="'+cval+'" type="hidden">');
             $B.DomUtils.append($wap,$in);
             $B.switchCtl( $in,{
                 trueText:"是",
                 falseText:"否",
                 notReturn:true,
                 onChange:switchEnable
             });
             return false;
         }
    </script>
</body>
</html>
